package com.ujs.code.shuzu;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * 给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数。
 * 输入: nums = [1,2,3,4,5,6,7], k = 3
 * 输出: [5,6,7,1,2,3,4]
 * 解释:
 * 向右轮转 1 步: [7,1,2,3,4,5,6]
 * 向右轮转 2 步: [6,7,1,2,3,4,5]
 * 向右轮转 3 步: [5,6,7,1,2,3,4]
 *
 * @author zhangshihao
 * @create 2023-09-08 19:59
 */
public class Rotate {
    public static void main(String[] args) {
        Rotate rotate = new Rotate();
        int[] nums = {1, 2, 3, 4, 5, 6, 7};
        int k = 3;
        rotate.rotate(nums, k);
    }

    public void rotate(int[] nums, int k) {
        ArrayList<Integer> numListPre = new ArrayList<>();
        ArrayList<Integer> numListPos = new ArrayList<>();
        int m = k % nums.length;
        System.out.println(m);
        for (int i = 0; i < nums.length; i++) {
            if (i < m) {
                numListPre.add(nums[i]);
            } else {
                numListPos.add(nums[i]);
            }
        }
        System.out.println(numListPre);
        System.out.println(numListPos);
    }
}
